package com.webchat.ugc.mongodb.inter;

import com.webchat.ugc.mongodb.document.MallChatMessage;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;

import java.util.Date;
import java.util.List;
import java.util.Map;

public interface IMallChatMessageRepository extends MongoRepository<MallChatMessage, String> {


    @Query("{'$and': [ " +
            "{'$or': [ " +
            "{'senderId': ?0, 'receiverId': ?1}, " +
            "{'senderId': ?1, 'receiverId': ?0} " +
            "]}, " +
            "{'sendDate': {?3 : ?2}} " +
            "]}")
    List<MallChatMessage> findChatMessagesBetweenUsersBeforeDate(String account,
                                                                 String chatAccount,
                                                                 Date lastDate,
                                                                 String sendDateCondition,
                                                                 Pageable pageable);

    /**
     * 查询发送人给接收人的未读消息数量
     *
     * @param senderId
     * @param receiverId
     * @return
     */
    Long countBySenderIdAndReceiverIdAndRead(String senderId, String receiverId, boolean read);
}
